package com.acme.entity.util;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

public class DBManager {

    private static EntityManager em = Persistence.createEntityManagerFactory("ProyectoCarreterasPU").createEntityManager();
    private static EntityChangeListener listener = new EntityChangeListener();

    public static EntityManager getEntityManager() {
        return em;
    }

    public static EntityChangeListener getListener(){
        return listener;
    }

    public static void persist(EntityBean bean) {
        em.getTransaction().begin();
        em.persist(bean);
        em.merge(bean);
        em.getTransaction().commit();
    }

    public static void remove(EntityBean bean) {
        em.getTransaction().begin();
        em.remove(bean);
        em.getTransaction().commit();
    }

}
